/*
 * JQuery floatBar Plugin
 *
 * Version: 2.99 (12-MAR-2011)
 * Licensed: New BSD Licensed
 * Requires: jQuery v1.3.2 or later
 * Copyright (c) 2011 Tony Chi (qiwei219@gmail.com)
 * Blog: http://tonychi.cnblogs.com
 *
 * For Example: 
	$("#demo").floatBar({ offset: 120, duration: 250 });
 *
 */
(function($) {
	$.fn.extend({
		floatBar: function(options) {
			var obj = $(this),
			    defaults = { top: 0, side: 'right', sideOffset: 0, duration: 500 },
			    params = $.extend(defaults, options || {}),
			    css = {'top': params.top, 'position': 'absolute' };

			css[(params.side == 'right' || params.side == 'left') ? params.side : defaults.side] = params.sideOffset;

			obj.css(css);

			$(window).scroll(function() {
				var bodyTop = 0;
				if (typeof window.pageYOffset != 'undefined') {
					bodyTop = window.pageYOffset
				} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
					bodyTop = document.documentElement.scrollTop
				} else if (typeof document.body != 'undefined') {
					bodyTop = document.body.scrollTop
				}

				obj.animate({top: params.top + bodyTop}, { duration: params.duration, queue: false });
			});
		}
	});
})(jQuery);
